package com.heima.wemedia.controller.v1;

import com.heima.common.constants.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈辉
 * @data 2023 11:29
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findAll(dto);
    }

    /**
     * 发布文章
     *
     * @param dto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }

    /**
     * 文章上下架
     *
     * @param dto
     * @return
     */
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }

    /**
     * 文章列表查询
     *
     * @param dto
     * @return
     */
    @PostMapping("list_vo")
    public ResponseResult list(@RequestBody NewsAuthDto dto) {
        return wmNewsService.Alllist(dto);
    }

    /**
     * 查询文章详情
     */
    @GetMapping("one_vo/{id}")
    public ResponseResult queryArticle(@PathVariable Integer id) {
        return wmNewsService.queryArticle(id);
    }

    /**
     * 人工审核文章失败
     */
    @PostMapping("auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto dto) {
        return wmNewsService.updateStatus(dto, WemediaConstants.WM_NEWS_AUTH_fAIL);
    }

    /**
     * 人工审核文章成功
     */
    @PostMapping("auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto dto) {
        return wmNewsService.updateStatus(dto,WemediaConstants.WM_NEWS_TYPE_PASS);
    }
}
